package refactoredBankSystem;

/**
 * The SavingsAccount class.
 * @author (refactorers) Sagar Kamboj, Yong Yu Wang
 *
 */
public class SavingsAccount {
	
	/**
	 * The account number of the savings account.
	 */
	private int fAccountNumber;
	
	/**
	 * The balance in the savings account.
	 */
	private double fBalance;
	
	/**
	 * Cost associated with the account.
	 */
	private static final double COSTS = 1; // per period there is a cost associated with this account
									// that equals 1 pound
	
	/**
	 * The interest rate on the savings account.
	 */
	private static double interestRate = 1.25;
	
	/**
	 * The next account number.
	 */
	private static int fNextAccountNumber = 0;
	
	/**
	 * The current customer of the savings account.
	 */
	private Customer currentCustomer;
	
	/**
	 * Creates a savings account with the given customer.
	 * 
	 * @param newCustomer  making a savings account.
	 */
	public SavingsAccount(final Customer newCustomer)
	{
		currentCustomer = newCustomer;
		fAccountNumber = fNextAccountNumber;
		fNextAccountNumber++;
	}
	
	/**
	 * Calculates the interest on the savings account.
	 */
	public void calculateInterest()
	{
		fBalance = fBalance + (fBalance * interestRate / 100);
	}
	
	/**
	 * Withdraws the amount specified from the savings account.
	 * @param amount that is to be withdrawn.
	 * @return if the amount is withdrawn.
	 */
	public boolean withdrawal(final double amount)
	{
		if(((fBalance - amount) < 0))
		{
			return false;
		}
		else
		{
			fBalance = fBalance - amount;
			return true;
		}
	}
	
	/**
	 * Adds that amount to the balance.
	 * @param amount added.
	 */
	public void verseMoney(final double amount)
	{
		fBalance += amount;
	}
	
	/**
	 * Print out the information of the bank account.
	 */
	public void print()
	{
		if (currentCustomer.getName() == null) {
			currentCustomer.setName("NO NAME INFO");
		}
		if (currentCustomer.getStreet() == null) {
			currentCustomer.setStreet("NO STREET INFO");
		}
		if (currentCustomer.getZipCode() == null) {
			currentCustomer.setZipCode("NO ZIPCODE INFO");
		}
		if (currentCustomer.getTown() == null) {
			currentCustomer.setTown("NO TOWN INFO");
		}
		if (currentCustomer.getCountry() == null) {
			currentCustomer.setCountry("NO COUNTRY INFO");
		}
		System.out.println("**************************************");
		System.out.println("Savings account:     " + fAccountNumber);
		System.out.println("Account holder name: " + currentCustomer.getName());
		System.out.println("Address:             " + currentCustomer.getStreet());
		System.out.print("                     " + currentCustomer.getZipCode());
		System.out.println(" " + currentCustomer.getTown());
		System.out.println(currentCustomer.getCountry().toUpperCase());
		System.out.println("**************************************");
		System.out.println("Balance:  " + fBalance);
		System.out.println("**************************************");
	}
	
	/**
	 * Sets the fBalance in this class to a new one.
	 * @param fBalance	the new fBalance to set.
	 */
	public void setFBalance(final double newNumber) {
		fBalance = newNumber;
	}
	
	/**
	 * Gets the fBalance object associated with this class.
	 * @return the fBalance 
	 */
	public double getFBalance() {
		return fBalance;
	}
	
	/**
	 * Get the current customer belonging to this class.
	 * @return	The current customer in this class.
	 */
	public Customer getCustomer() {
		return currentCustomer;
	}
	
	/**
	 * Sets the customer in this class to a new one.
	 * @param newCustomer	the new customer to set.
	 */
	public void setCustomer(final Customer newCustomer) {
		currentCustomer = newCustomer;
	}
	
	/**
	 * Get the current account number
	 * @return the account number.
	 */
	public int getAccountNumber() 
	{
		return fAccountNumber;	
	}
	
	/**
	 * Sets the accountNumber for this account to a new value.
	 * @param newNumber the new number to set.
	 */
	public void setAccountNumber(final int newNumber) 
	{
		fAccountNumber = newNumber;	
	}
	
	/**
	 * Get the fNextAccountNumber
	 * @return the account number.
	 */
	public int getFNextAccountNumber() 
	{
		return fNextAccountNumber;	
	}
	
	/**
	 * Sets the fNextAccountNumber for this account to a new value.
	 * @param newNumber the new number to set.
	 */
	public void setFNextAccountNumber(final int newNumber) 
	{
		fNextAccountNumber = newNumber;	
	}
	
	/**
	 * Get the current costs belonging to this class.
	 * @return	The current costs in this class.
	 */
	public double getCosts() {
		return COSTS;
	}
}
